package com.oocl.scp_ssh.analyze;

import com.oocl.scp_ssh.pojo.Command;
import com.oocl.scp_ssh.pojo.impl.LsCommand;
import com.oocl.scp_ssh.pojo.impl.RmCommand;
import com.oocl.scp_ssh.scp.ScpJudge;

public class CommandAnalzyer {
	
	private final String LS = "LS";
	private final String RM = "RM";
	private final String SCP = "scp";
	
	public Command analyzeCmd(String cmd) {
		if(cmd== null || cmd.length() ==0)
			return null;
		String[] ss = cmd.split("\\s");
		if(ss== null || ss.length==0)
			return null;
		switch(ss[0]) {
		case LS:
			///最多只有一个option，而且是个目录
			LsCommand lsCommand = new LsCommand();
			lsCommand.head = "LS";
			if(ss[1]!=null&& ss[1].length()>0)
				lsCommand.setDir(ss[1]);
			return lsCommand;
			
		case RM:
			///有一个option，而且是个文件名 或 目录
			if(ss[1]==null || ss[1].length()==0)
				return null;
			RmCommand rmCommand = new RmCommand();
			rmCommand.head = "RM";
			rmCommand.setDeleteFileName(ss[1]);
			return rmCommand;
		case SCP:
			return new ScpJudge().judge(cmd);
			default:
				return null;
				
		}
		
	}
	
}
